import Text from './text';
import Rectangle from './rectangle';
import Img from './img';
import Button from './button';
import ImgButton from './imgButton';
import Switch from './switch';
import Gauge from './gauge';
import Form from './form';
import Table from './table';
import ChartTypeLine from './chartTypeLine';
import Device from './device';
import Device2 from './device2';
import AlarmList from './alarmList';
import Component from './component';
import Input from './input';

const groups = [
  {
    name: '基础',
    children: [
      Text,
      Img,
      Rectangle,
      Input
    ]
  },
  {
    name: '控制',
    children: [
      Button,
      ImgButton,
      Switch
    ]
  },
  {
    name: '图表',
    children: [
      Gauge,
      Form,
      Table,
      ChartTypeLine
    ]
  },
  {
    name: '设备',
    children: [
      Device,
      Device2,
      AlarmList
    ]
  },
  {
    name: '其他',
    children: [
      Component
    ]
  }
];

export default {
  // 返回所有元件
  all() {
    const map = {};
    groups.reduce((previousValue, g) => {
      return previousValue.concat(g.children);
    }, []).forEach(item => {
      map[item.name] = item;
    });
    return map;
  },
  // 获取组件名称
  getTitle(name) {
    let all = this.all();
    const item = all[name];
    if (item) {
      return item.title;
    }
    return '';
  },
  // 返回分组的元件
  groups() {
    return groups;
  }

}
